package com.example.demo.service;

import com.example.demo.mapper.StudentMapper;
import com.example.demo.model.Student;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import java.util.List;

@Service // 标识为服务类
public class StudentServiceImpl implements StudentService {
	@Autowired
	private StudentMapper studentMapper;

	@Override
	public PageInfo<Student> getAll(Student student, int page, int size) {
		// 首先开启PageHelper的分页
		PageHelper.startPage(page, size);
		// 查询分页信息 调用方式与普通方式一致
		List<Student> list = studentMapper.selectAll(student);
		//生成PageInfo对象
		PageInfo<Student> pageInfo=new PageInfo<Student>(list);
		return pageInfo;
	}
	/**
	 *查询是否存在
	 * @return
	 */
	public Student selectByNo(int studentNo) {
		Student student=studentMapper.selectByPrimaryKey(studentNo);
		return student;
	}

	/**
	 * 增加学生信息
	 * @param student
	 * @return
	 */
	public Integer addStudent(Student student) {
		Integer total=studentMapper.insert(student);
		return total;
	}
	/**
	 * 修改学生信息
	 * @param student
	 * @return
	 */
	public Integer updateStudent(Student student) {
		Integer total=studentMapper.updateByPrimaryKey(student);
		return total;
	}


//	/**
//	 * 删除学生信息
//	 * @param student
//	 * @return
//	 */
	public Integer deleteStudent(int studentNo) {
		Integer total=studentMapper.deleteByPrimaryKey(studentNo);
		return total;
	}
	/**
	 *全量查询用户为下拉框
	 * @return
	 */
	public List<Student> selectAllStudent(){
		return studentMapper.selectAll(null);
	}

//	/**
//	 * 查询学生账号信息
//	 * @param record
//	 * @return
//	 */
	public List<Student> selectloginStudent(Student student){
		return studentMapper.selectloginStudent(student);
	}
}
